iT邦幫忙

DAY 16
0

用Packer, Vagrant和Salt秒殺你的環境建置系列 第 16

Day 16 - Packer Linux template

  • 分享至 

  • xImage
  •  

分享一個 packer template 檔

來源:https://github.com/shiguredo/packer-templates/blob/develop/ubuntu-14.04/template.json

這是一個建立 ubuntu 的 template 檔

你只要下 packer build template.json 就可以建立 virtualbox 和 vmware 的 box

{
  "post-processors": [
    {
      "type": "vagrant",
      "keep_input_artifact": true,
      "output": "{{user `vm_name`}}_{{.Provider}}.box"
    }
  ],
  "provisioners": [
    {
      "type": "shell",
      "execute_command": "echo 'vagrant'|sudo -S sh '{{.Path}}'",    
      "override": {
        "virtualbox-iso": {
          "scripts": [
            "linux-script/base.sh",
            "linux-script/vagrant.sh",
            "linux-script/virtualbox.sh",
            "linux-script/cleanup.sh",
            "linux-script/zerodisk.sh"
          ]
        },
        "vmware-iso": {
          "scripts": [
            "linux-script/base.sh",
            "linux-script/vagrant.sh",
            "linux-script/vmware.sh",
            "linux-script/cleanup.sh",
            "linux-script/zerodisk.sh"
          ]
        }
      }
    }
  ],
  "builders": [
    {
      "type": "virtualbox-iso",
      "boot_command": [
        "<esc><wait>",
        "<esc><wait>",
        "<enter><wait>",
        "/install/vmlinuz<wait>",
        " auto<wait>",
        " console-setup/ask_detect=false<wait>",
        " console-setup/layoutcode=us<wait>",
        " console-setup/modelcode=pc105<wait>",
        " debconf/frontend=noninteractive<wait>",
        " debian-installer=en_US<wait>",
        " fb=false<wait>",
        " initrd=/install/initrd.gz<wait>",
        " kbd-chooser/method=us<wait>",
        " keyboard-configuration/layout=USA<wait>",
        " keyboard-configuration/variant=USA<wait>",
        " locale=en_US<wait>",
        " netcfg/get_hostname=ubuntu-1404<wait>",
        " netcfg/get_domain=vagrantup.com<wait>",
        " noapic<wait>",
        " preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg<wait>",
        " -- <wait>",
        "<enter><wait>"
      ],
      "boot_wait": "10s",
      "disk_size": 40960,
      "headless": true,
      "guest_os_type": "Ubuntu_64",
      "http_directory": "http",
      "iso_checksum": "01545fa976c8367b4f0d59169ac4866c",
      "iso_checksum_type": "md5",
      "iso_url": "{{user `iso_folder`}}/ubuntu-14.04-server-amd64.iso",
      "ssh_username": "vagrant",
      "ssh_password": "vagrant",
      "ssh_port": 22,
      "ssh_wait_timeout": "10000s",
      "shutdown_command": "echo 'shutdown -P now' > /tmp/shutdown.sh; echo 'vagrant'|sudo -S sh '/tmp/shutdown.sh'",
      "vboxmanage": [
        [ "modifyvm", "{{.Name}}", "--memory", "512" ],
        [ "modifyvm", "{{.Name}}", "--cpus", "1" ]
      ]
    },
    {
      "type": "vmware-iso",
      "boot_command": [
        "<esc><wait>",
        "<esc><wait>",
        "<enter><wait>",
        "/install/vmlinuz<wait>",
        " auto<wait>",
        " console-setup/ask_detect=false<wait>",
        " console-setup/layoutcode=us<wait>",
        " console-setup/modelcode=pc105<wait>",
        " debconf/frontend=noninteractive<wait>",
        " debian-installer=en_US<wait>",
        " fb=false<wait>",
        " initrd=/install/initrd.gz<wait>",
        " kbd-chooser/method=us<wait>",
        " keyboard-configuration/layout=USA<wait>",
        " keyboard-configuration/variant=USA<wait>",
        " locale=en_US<wait>",
        " netcfg/get_hostname=ubuntu-1404<wait>",
        " netcfg/get_domain=vagrantup.com<wait>",
        " noapic<wait>",
        " preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg<wait>",
        " -- <wait>",
        "<enter><wait>"
      ],
      "boot_wait": "10s",
      "disk_size": 40960,
      "headless": true,
      "guest_os_type": "ubuntu-64",
      "tools_upload_flavor": "linux",
      "http_directory": "http",
      "iso_checksum": "ca2531b8cd79ea5b778ede3a524779b9",
      "iso_checksum_type": "md5",
      "iso_urls": [
          "{{user `iso_folder`}}/ubuntu-14.04.1-server-amd64.iso "
        ],
      "ssh_username": "vagrant",
      "ssh_password": "vagrant",
      "ssh_port": 22,
      "ssh_wait_timeout": "10000s",
      "shutdown_command": "echo 'shutdown -P now' > /tmp/shutdown.sh; echo 'vagrant'|sudo -S sh '/tmp/shutdown.sh'",
      "vmx_data": {
        "memsize": "512",
        "numvcpus": "1",
        "cpuid.coresPerSocket": "1"
      }
    }
  ]
}

上一篇
Day 14 - Packer
系列文
用Packer, Vagrant和Salt秒殺你的環境建置16
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言